<?php
	require_once( 'core_DataBaseConnect.php' );
	require_once( 'core_Response.php' );
	require_once( 'core_ErrorCode.php' );
	require_once( 'dao_SettingDAO.php' );
	require_once( '_configs.php' );
	
	function func( $con, $post, $returnType )
	{
		$response = array();
		
		// 지역 설정 정보
		$result = SettingDAO::selectRegion( $con );
		$response[ 'region' ] = array();
		$response[ 'region' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'region' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'PARENT_CODE', 'IMAGE_URL' ) ) );
		}
		// 교육 설정 정보
		$result = SettingDAO::selectEducation( $con );
		$response[ 'education' ] = array();
		$response[ 'education' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'education' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'LEVEL' ) ) );
		}
		// 군복무 설정 정보
		$result = SettingDAO::selectMilitary( $con );
		$response[ 'military' ] = array();
		$response[ 'military' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'military' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'LEVEL' ) ) );
		}
		// 정당 설정 정보
		$result = SettingDAO::selectParty( $con );
		$response[ 'party' ] = array();
		$response[ 'party' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'party' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'IMAGE_URL' ) ) );
		}
		// 직급 목록
		$result = SettingDAO::selectRank( $con );
		$response[ 'rank' ] = array();
		$response[ 'rank' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'rank' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'LEVEL', 'IMAGE_URL' ) ) );
		}
		// 직책 목록
		$result = SettingDAO::selectDuty( $con );
		$response[ 'duty' ] = array();
		$response[ 'duty' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'duty' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'RANK_CODE', 'IMAGE_URL' ) ) );
		}
		// 완수 목록
		$result = SettingDAO::selectCompleted( $con );
		$response[ 'completed' ] = array();
		$response[ 'completed' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'completed' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME' ) ) );
		}
		// 사업구분 목록
		$result = SettingDAO::selectBusiness( $con );
		$response[ 'business' ] = array();
		$response[ 'business' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'business' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'LEVEL' ) ) );
		}
		// 약력 구분 목록
		$result = SettingDAO::selectHistory( $con );
		$response[ 'history' ] = array();
		$response[ 'history' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'history' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME' ) ) );
		}
		// SNS 구분 목록
		$result = SettingDAO::selectSns( $con );
		$response[ 'sns' ] = array();
		$response[ 'sns' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'sns' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME' ) ) );
		}
		// 투표 구분 목록
		$result = SettingDAO::selectVote( $con );
		$response[ 'vote' ] = array();
		$response[ 'vote' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'vote' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'POINT' ) ) );
		}
		// 참여구분 목록
		$result = SettingDAO::selectAction( $con );
		$response[ 'action' ] = array();
		$response[ 'action' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'action' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'POINT' ) ) );
		}
		// 능력치
		$result = SettingDAO::selectStat( $con );
		$response[ 'stat' ] = array();
		$response[ 'stat' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'stat' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME', 'GROUP' ) ) );
		}
		// 가입 플랫폼
		$result = SettingDAO::selectRegistPlatform( $con );
		$response[ 'platform' ] = array();
		$response[ 'platform' ][ 'item' ] = array();
		while( $fetch = DataBaseConnect::fetch_assoc( $result ) )
		{
			array_push( $response[ 'platform' ][ 'item' ], DataBaseConnect::fetchSerialize( $fetch, array( 'CODE', 'NAME' ) ) );
		}
		
		// 메뉴 항목
		$menus = array();
		// 메뉴1 - 직책&직급
		foreach( $response[ 'rank' ][ 'item' ] as $rank )
		{
			$obj = insertMenuItem( $menus, 'rank', $rank[ 'code' ], $rank[ 'name' ], $rank[ 'image_url' ] );
			foreach( $response[ 'duty' ][ 'item' ] as $duty )
			{
				if( $rank[ 'code' ] == $duty[ 'rank_code' ] )
				{
					insertMenuItem( $menus, 'duty', $duty[ 'code' ], $duty[ 'name' ], $duty[ 'image_url' ], $obj[ 'id' ] );
				}
			}
		}
		// 메뉴2 - 정당
		/* 
		- 정치인이 rank 와 duty 추가됨..
		- 정작, 당선 히스토리는 쓰지 않음
		$obj = insertMenuItem( $menus, 'party', configs::NULL_PARTY_CODE, '정치인', '' );	// 정당1뎁스는 임의로 넣는다.
		foreach( $response[ 'party' ][ 'item' ] as $party )
		{
			insertMenuItem( $menus, 'party', $party[ 'code' ], $party[ 'name' ], $party[ 'image_url' ], $obj[ 'id' ] );
		}
		*/
		$response[ 'menu' ] = array();
		$response[ 'menu' ][ 'item' ] = array_merge( $menus );
		
		// 이미지 서버
		$response[ 'imageServerPath' ] = configs::IMAGE_SERVER_PATH;
		
		return Response::SUCCESS( $response, $returnType );
	}
	
	function insertMenuItem( &$container, $type, $code, $name, $image_url, $parent_id = -1 )
	{
		$obj 					= array();
		$obj[ 'id' ] 			= count( $container );
		$obj[ 'type' ] 			= $type;
		$obj[ 'code' ] 			= $code;		
		$obj[ 'name' ] 			= $name;
		$obj[ 'image_url' ] 	= $image_url;
		$obj[ 'parent_id' ]		= $parent_id;
		
		array_push( $container, $obj );
		
		return $obj;
	}
?>